package cn._2dland.bots.servlets;

import java.io.IOException;

import javax.servlet.ServletException;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import com.google.appengine.api.users.UserService;
import com.google.appengine.api.users.UserServiceFactory;

@SuppressWarnings("serial")
public class Controller extends HttpServlet {
	protected void doGet(HttpServletRequest req, HttpServletResponse resp)
			throws ServletException, IOException {
		UserService serv = UserServiceFactory.getUserService();
		if(serv.isUserLoggedIn()){
			req.getRequestDispatcher("/WEB-INF/pages/index.jsp").forward(req, resp);
		}
		else{
			String loginURL = serv.createLoginURL("/");
			resp.sendRedirect(loginURL);
		}
	}

	protected void doPost(HttpServletRequest req, HttpServletResponse resp)
			throws ServletException, IOException {
		doGet(req, resp);
	}
}
